package com.ruoyi.dev.minio.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.dev.minio.domain.MinioFile;
import com.ruoyi.dev.minio.mapper.MinioFileMapper;
import com.ruoyi.dev.minio.service.MinioFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.Date;
import java.util.List;

/**
 * @author sxy
 * @date 2024/02/26
 **/
@Service
public class MinioFileServiceImpl extends ServiceImpl<MinioFileMapper, MinioFile> implements MinioFileService {

    @Autowired
    public MinioFileMapper minioFileMapper;

    @Override
    public boolean insert(MinioFile minioFile) {
        minioFile.setCreateTime(new Date());
        minioFile.setUpdateTime(new Date());
        minioFile.setCreateBy(SecurityUtils.getUsername());
        minioFile.setUpdateBy(SecurityUtils.getUsername());
        int insert = minioFileMapper.insert(minioFile);
        Assert.isTrue(insert == 1, "插入失败！");

        return true;
    }

    @Override
    public List<MinioFile> selectList() {
        LambdaQueryWrapper<MinioFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(MinioFile::getIsDelete, 1);
        List<MinioFile> minioFiles = minioFileMapper.selectList(lambdaQueryWrapper);

        return minioFiles;
    }
}
